"""
封装执行shell语句方法
"""

import subprocess
from util.report import log_tool


def invoke(cmd):
    """执行shell语句函数

    :param cmd: 命令

    :return:
    """
    try:
        output, errors = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
        o = output.decode("utf-8")
        print(o)
        return o
    except Exception as e:
        log_tool.error('执行命令失败，请检查环境配置')
        log_tool.error(e)
        raise

